package 内存结构.堆;

public class 内存诊断jmap {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("1...");
        Thread.sleep(30000);
        /*
        没有创建对象，堆没有东西
        Eden Space:
            capacity = 67108864 (64.0MB)
            used     = 6710992 (6.4001007080078125MB)
         */
        byte[] array = new byte[1024 * 1024 * 10]; // 10 Mb
        System.out.println("2...");
        Thread.sleep(20000);
        /*
        创建对象后，堆里多了东西16.400115966796875MB
        Eden Space:
            capacity = 67108864 (64.0MB)
            used     = 17196768 (16.400115966796875MB)
         */
        array = null;
        System.gc();
        System.out.println("3...");
        Thread.sleep(1000000L);
        /*
        垃圾回收后，堆里没有东西
        Eden Space:
            capacity = 67108864 (64.0MB)
            used     = 1342200 (1.2800216674804688MB)
         */
    }

}
